from litemall_0805.frame.pages.home_page import HomePage
from selenium.webdriver.common.by import By


class GoodsCategoryList(HomePage):
    """
    实现【商品类目列表】页面的功能，如：增加按键、删除按键、相应操作的测试结果等
    """
    def click_add_category(self):
        """
        实现【添加】按键的点击
        :return:
        """
        self.do_click(By.CSS_SELECTOR, ".el-button--primary")

        from litemall_0805.frame.pages.mall_manage.add_category_page import AddCategoryPage
        return AddCategoryPage(self.driver)

    def get_add_result(self):
        """
        实现【添加】功能的测试结果
        :return: 创建成功
        """
        add_result = self.wait_visible_locate(By.XPATH, "//*[text()='创建成功']")
        return add_result.text

    def click_del_category(self, category_name):
        """
        实现【删除】按键的点击
        :param category_name:
        :return:
        """
        self.do_click(By.XPATH, f"//*[text()='{category_name}']/../..//*[text()='删除']")
        return self

    def get_del_result(self):
        """
           实现【删除】能的测试结果
           :return: 删除成功
       """
        del_element = (By.XPATH, "//*[text()='删除成功']")
        del_result = self.wait_visible_locate(del_element)
        return del_result.text
